<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:p="http://primefaces.org/ui"
	template="/WEB-INF/templates/template.xhtml">
    <ui:define name="content">
    <h:form>
    <div id="iddiv" align="center" style="width : 800px;font-size: 10pt" >
    <br />
    <p:panel id="idpanel" rendered="#{medicationBean.action == 'delete' || medicationBean.action == 'find' || medicationBean.action == 'update'}">
    	<h:message for="medicationId"/>
    	<f:facet name="header">
    		<h:outputText value="Find Medication By ID" />
		</f:facet>
    	<h:panelGrid columns="3">
    				<h:outputText value="Medication Id: " />
        			<p:inputText value="#{medicationBean.medicationId}" id="medicationId" required="true" />
        			<h:commandButton action="#{medicationBean.findMedicationById}" value="Search" />
    	</h:panelGrid>
    </p:panel>
    </div>
    </h:form>
    <h:form id="form" align="center">
    	<f:metadata>
    		<f:viewParam name="action" value="#{medicationBean.action}" />
		</f:metadata>
		<div id="block" align="center" style="width : 800px; font-size: 10pt" >
		<p:panel id="panel">
        	<h:outputText  value="Please enter search criteria, if non is entered search will return all medications" 
        	rendered="#{medicationBean.action == 'delete' || medicationBean.action == 'find' || medicationBean.action == 'delete'}"/>
        	<f:facet name="header" >
        	<h:outputText  value="Please Enter Information for New Medication" 
        	rendered="#{medicationBean.action == 'create'}" />
        	<h:outputText  value="Update Medication" 
        	rendered="#{medicationBean.action == 'update'}" />
        	<h:outputText  value="Delete Medication" 
        	rendered="#{medicationBean.action == 'delete'}" />
        	<h:outputText  value="Find By Multiple Criteria" 
        	rendered="#{medicationBean.action == 'find'}" />
        	</f:facet><br/><br/>
    		
        		<h:panelGrid columns="5" style="margin-right:10px; cellspacing : 10pt">
        			
        			<h:outputText value="Generic Name: " />
        			<p:inputText value="#{medicationBean.medication.genericName}"  rendered="#{medicationBean.action == 'update' || medicationBean.action == 'create'}" />
        			<p:inputText value="#{medicationBean.medication.genericName}"  readonly="true" rendered="#{medicationBean.action == 'delete' || medicationBean.action == 'find'}" />
        			<p:spacer width="30" />
        			<h:outputText value="Medication Name: " />
        			<p:inputText value="#{medicationBean.medication.medicationName}" rendered="#{medicationBean.action == 'update' || medicationBean.action == 'create'}" />
        			<p:inputText value="#{medicationBean.medication.medicationName}" readonly="true" rendered="#{medicationBean.action == 'delete' || medicationBean.action == 'find'}" />
        			
        			<h:outputText value="UPC code" />
        			<p:inputText value="#{medicationBean.medication.upcCode}"  rendered="#{medicationBean.action == 'update' || medicationBean.action == 'create'}" />
        			<p:inputText value="#{medicationBean.medication.upcCode}" readonly="true" rendered="#{medicationBean.action == 'delete' || medicationBean.action == 'find'}" />
        			<p:spacer width="30" />
        			<h:outputText value="Medication Strength: " />
        			<p:inputText value="#{medicationBean.medication.medicationStrength}"  rendered="#{medicationBean.action == 'update' || medicationBean.action == 'create'}" />
        			<p:inputText value="#{medicationBean.medication.medicationStrength}"  readonly="true" rendered="#{medicationBean.action == 'delete' || medicationBean.action == 'find'}" />
        			
        			
        			
        			<h:outputText value="Medication Class: " />
        			<p:inputText value="#{medicationBean.medication.medicationClass}"  rendered="#{medicationBean.action == 'update' || medicationBean.action == 'create'}" />
        			<p:inputText value="#{medicationBean.medication.medicationClass}" readonly="true" rendered="#{medicationBean.action == 'delete' || medicationBean.action == 'find'}" />
        			<p:spacer width="30" />
        			<h:outputText value="Dosage Form: " />
        			<p:inputText value="#{medicationBean.medication.dosageForm}"  rendered="#{medicationBean.action == 'update' || medicationBean.action == 'create'}" />
        			<p:inputText value="#{medicationBean.medication.dosageForm}"  readonly="true" rendered="#{medicationBean.action == 'delete' || medicationBean.action == 'find'}" />
        			
        		</h:panelGrid>
        		<br/>
        		<h:panelGrid  rows="2">
        		<h:outputText value="Medication Description: " />
        		<p:inputTextarea value="#{medicationBean.medication.medicationDesc}" style="width : 545px" rendered="#{medicationBean.action == 'update' || medicationBean.action == 'create'}" />
        		<p:inputTextarea value="#{medicationBean.medication.medicationDesc}" style="width : 545px" readonly="true" rendered="#{medicationBean.action == 'delete' || medicationBean.action == 'find'}" />
        		</h:panelGrid>
        		<br/>
        		<br/>
        			
        			<p:commandButton value="Reset" action="#{medicationBean.reset}" update="panel" process="@this"  /> 
        			<p:commandButton value="Find" action="#{medicationBean.findMedicationByColumns}" update="medications, panel" rendered="#{medicationBean.action == 'find' || medicationBean.action == 'update' || medicationBean.action == 'delete'}"/>
        			<p:commandButton value="Create" action="#{medicationBean.createMedication}" update="medications, panel" rendered="#{medicationBean.action == 'create'}" oncomplete="alert('Medication created!!!')"/>
        			<p:commandButton value="Update" action="#{medicationBean.updateMedication}" update="medications, panel" rendered="#{medicationBean.action == 'update'}" oncomplete="alert('Medication updated!!!')"/>
        			<p:commandButton value="Delete" action="#{medicationBean.deleteMedication}" update="medications, panel" rendered="#{medicationBean.action == 'delete'}" oncomplete="alert('Medication deleted!!!')"/>
        			<p:commandButton value="Previous" action="#{medicationBean.previous}" rendered="#{medicationBean.listReturned}" update="panel"/>
        			<p:commandButton value="Next" action="#{medicationBean.next}" rendered="#{medicationBean.listReturned}"  update="panel"/>
        			<p:commandButton value="Cancel" onclick="location.href='medicationhome.jsf'"/>
        			
        	<br /><br />
        	<p:dataTable id="medications" var="medications" value="#{medicationBean.medicationList}" style="width : 750px; font-size : 8pt" styleClass="wrap">
			
			<f:facet name="header">Results</f:facet>
			<p:column headerText="Id" sortBy="#{medication.medicationId}">#{medications.medicationId}</p:column>
			<p:column headerText="Med. Name" sortBy="#{medication.medicationName}">#{medications.medicationName}</p:column>
			<p:column headerText="Generic Name" sortBy="#{medication.genericName}">#{medications.genericName}</p:column>
			<p:column headerText="Med. Dosage" sortBy="#{medication.dosageForm}">#{medications.dosageForm}</p:column>
			<p:column headerText="Med. Class" sortBy="#{medication.medicationClass}">#{medications.medicationClass}</p:column>
			<p:column headerText="Med. Strength" sortBy="#{medication.medicationStrength}">#{medications.medicationStrength}</p:column>
			<p:column headerText="UPC Code" sortBy="#{medication.upcCode}">#{medications.upcCode}</p:column>
    		</p:dataTable>
    		
    		</p:panel>
		</div>

		</h:form>

    </ui:define>
</ui:composition>
